package service;

import java.util.Calendar;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import model.Locavel;
import model.Reserva;

public class ReservaDAO extends GenericDAOImpl<Reserva> {
	
	public ReservaDAO(EntityManager em) {
		super.entityManager = em;
	}
	
	public Reserva criaReserva(Calendar dataReserva, Locavel locavel) {
		Reserva res = new Reserva();
		res.setDataReserva(dataReserva);
		res.setLocavel(locavel);
		
		insereObjeto(res);
		
		return res;
	}

	@Override
	public Reserva localizaObjeto(Long objId) {
		Reserva obj = entityManager.getReference(Reserva.class, objId);
		return obj;
	}

	@Override
	public List<Reserva> listaObjetos() {
		TypedQuery<Reserva> query = entityManager.createQuery(
				"SELECT e FROM Reserva e", Reserva.class);
		return query.getResultList();
	}

	@Override
	public void deletaObjetos() {
		TypedQuery<Reserva> query = entityManager.createQuery(
				"DELETE FROM Reserva", Reserva.class);
		query.executeUpdate();
	}

}
